*Inferring the environmental protection costs by enterprises*

*cd "/RFS_replication_package/Martinsson_et_al_datasets"

use "new_miljoskydd_stack.dta",clear 



/*(Remove here to get the original codes used in the paper)




*Aggregating costs*

egen total_du= rowtotal(extdukost intdukost)
label var total_du "sum of running costs"
egen total_other=rowtotal(madmkost foukost ovrkost)
label var total_other "sum of other costs"
egen total_investment=rowtotal(invftot invbtot)
label var total_investment "sum of investments"

egen total_pace=rowtotal(total_du total_other total_investment)

gen pace_opx=total_du+total_other
rename total_investment pace_capex
label var total_pace "Sum of PACE Components"


merge 1:1 bidnr year using "test_11.dta"

drop if _merge==1
drop _merge

*Per employee figure: first try*

g env_cost_empl=total_pace/antanst  /*per employee*/

*aggregate up to sni2007 4d:
bysort sni2007_4d year: egen sni2007_4d_total_pace=sum(total_pace)
*/

merge 1:1 bidnr year using "master_file_with_fuels_noemissions.dta"

drop if _merge==1
drop _merge

merge 1:1 bidnr year using  "Investeringsenkaten.dta" 

drop if _merge==2
drop _merge

bysort sni2007_4d year: egen sni2007_4d_total_ibygg=sum(IBygg)
bysort sni2007_4d year: egen sni2007_4d_total_imask=sum(IMask)

sort bidnr year, stable 
order bidnr year tj - IMask
save "master_file_with_fuels_noemissions_w_inv.dta" , replace




*Same for the emission_req file
use "new_miljoskydd_stack.dta",clear 

merge 1:1 bidnr year using "master_file_with_fuels_emissions.dta"

drop if _merge==1
drop _merge

merge 1:1 bidnr year using  "Investeringsenkaten.dta" 

drop if _merge==2
drop _merge

bysort sni2007_4d year: egen sni2007_4d_total_ibygg=sum(IBygg)
bysort sni2007_4d year: egen sni2007_4d_total_imask=sum(IMask)

sort bidnr year, stable 
order bidnr year tj - IMask
save "master_file_with_fuels_emissions_w_inv.dta", replace



